<!--阅卷-->
<template>
  <a-modal
    :maskClosable="false"
    title="阅卷"
    :width="1000"
    @ok="createData()"
    v-model="mdl.visible"
    :confirm-loading="loading"
  >
    <a-form v-for="(item,index) in list">
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="题目"
      >
        {{index+1}}、<a-input placeholder="" style="width: 95%" disabled v-model="item.questionTitle"/>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="正确答案"
      >
        <a-textarea :rows="4" disabled v-model="item.answer"/>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="用户答案"
      >
        <a-textarea :rows="4" disabled v-model="item.answerReply"/>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="分数"
      >
        <a-input-number v-model="item.score" :min="0" :max="item.qscore"/>  最多{{item.qscore}}分
      </a-form-item>
    </a-form>
    <div>

    </div>
  </a-modal>
</template>
<script>
  import {examAnswerRecord,checkPageForQuestion,examRecordqrcode} from '@/api/examManage/questionBankManage'
export default {
  components: {

  },
  props: {
    /*   -------弹窗-------- */
    mdl:[Object,Array]
  },
  data () {
    return {
      list: [],
      loading: false
    }
  },
  inject: ['upShow'],

  created () {

  },
  watch: {
    ids(value) {
        this.getList(value)
    }
  },
  computed: {
    ids() {
        return this.mdl.formData.id
    }
  },
  methods: {
    getList(id) {
        var params = {
          "_search": false,
          "data": {
            "questionType": 3
          },
          "selectedType": "exam_record_id",
          "type": id
        }
      examAnswerRecord(params).then(res=> {
        if(res.code==200) {
            this.list = res.data
        }
      })
    },
    // 确定阅卷
    createData () {
        this.loading = true
      var scores = this.mdl.formData.score
        this.list.forEach((item,index)=> {
            if(index==this.list.length-1) {
                var isCheck = 1
            }else {
              var isCheck = 2
            }
          var params = {
            "_search": false,
            "bgTm": "",
            "data": {
              "examTitleId":item.examTitleID, // 考试id 对应点击阅卷接口examTitleID
              "examRecordId":item.examRecordId,// 考试记录id //对应点击阅卷接口examRecordId
              "id":item.id, // 答题（简答题）记录id  对应点击阅卷接口id
              "score":item.score, // 打分
              isCheck: isCheck
            }
          }
          scores = scores + item.score
          checkPageForQuestion(params).then(res=> {
            if(res.code==200) {
                if(index==this.list.length-1) {
//                    下发证书
//                  console.log('scores:' + scores);
//                  console.log('this.mdl.formData.passGrade:' + this.mdl.formData.passGrade);
//                  console.log('this.mdl.formData.memberId:' + this.mdl.formData.memberId);
                  if(scores>=this.mdl.formData.passGrade && this.mdl.formData.eid==0) {
                      examRecordqrcode({memberId:this.mdl.formData.memberId}).then(res1=> {

                      })
                    }
                  this.loading = false
                  this.upShow(1,'提交成功')
                  this.$emit('handleSearch')
                }
            }else {
              this.loading = false
              this.upShow(2,'提交失败')
            }
          }) .catch(err => {
            this.loading = false
            this.upShow(2,'提交失败')
          })
        })
    }
  }
}
</script>
